home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 11.2 KB | 408 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Proxy.cpp
- // Release Version: $ ODF 2 $
- //
- // Author: M.Boetcher
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Embed.hpp"
-
- // ----- Embed Part Includes -----
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- // ----- ODF Includes -----
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWFCTCLP_H
- #include "FWFctClp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPXYITE_H
- #include "FWPxyIte.h"
- #endif
-
- #ifndef FWMENUS_K
- #include "FWMenus.k"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfembed
- #endif
-
- //========================================================================================
- // class CEmbedProxy
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy constructors
- //----------------------------------------------------------------------------------------
-
- CEmbedProxy::CEmbedProxy(Environment* ev, CEmbedPart* part) :
- FW_MProxy(ev, part),
- fPart(part)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy::~CEmbedProxy
- //----------------------------------------------------------------------------------------
-
- CEmbedProxy::~CEmbedProxy()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy::AdjustBorderShape
- //----------------------------------------------------------------------------------------
- void CEmbedProxy::AdjustBorderShape(Environment* ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFacet* embeddedFacet,
- ODShape* shape)
- {
- FW_UNUSED(embeddingFrame);
- FW_UNUSED(embeddedFacet);
-
- // Don't draw border shape when there are 4 facets because it looks too messy
- if (shape != 0 && fPart->FacetNumber() != cOneFacet)
- shape->Reset(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy::UsedShapeChanged
- //----------------------------------------------------------------------------------------
- // Used shape of an embedded frame changed. Just invalidate and recalculate its clip
-
- void CEmbedProxy::UsedShapeChanged(Environment* ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFrame* odEmbeddedFrame)
- {
- FW_UNUSED(odEmbeddedFrame);
-
- // ----- Recalculate the clip -----
- if (fPart->FacetNumber() == cOneFacet)
- {
- // ----- Use the standard facet clipper
- FW_CFacetClipper clipper;
- clipper.Clip(ev, embeddingFrame);
- }
- else
- {
- // I cannot use the standard facet clipper because it only works for one facet
- // Because I know in which order the facets were created I can just iterates
- FW_CRect clipRects[4];
- EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
-
- short rotation = fPart->GetRotation();
-
- FW_CFrameFacetIterator ite(ev, embeddingFrame);
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- short facetID = 0;
- FW_CFacetIterator ite2(ev, facet);
- for (ODFacet* embeddedFacet = ite2.First(ev); ite2.IsNotComplete(ev); embeddedFacet = ite2.Next(ev))
- {
- FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRects[facetID]);
-
- FW_CAcquiredODShape aqClipShape = FW_NewODShape(ev, clipRects[facetID]);
-
- // Update the facet clip shape
- embeddedFacet->ChangeGeometry(ev, aqClipShape, externalTransform, NULL);
- facetID++;
- }
- }
- }
-
- embeddingFrame->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy::RotateFacets
- //----------------------------------------------------------------------------------------
-
- void CEmbedProxy::RotateFacets(Environment* ev, short rotation)
- {
- // Loop on all proxy frames
- FW_CProxyProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- FW_CEmbeddingFrame* embeddingFrame = proxyFrame->GetContainingFrame(ev);
- if (embeddingFrame == NULL)
- continue;
-
- FW_CRect clipRects[4];
- EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
-
- // Loop on all facets of the embedding frame
- FW_CFrameFacetIterator ite(ev, embeddingFrame);
- for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
- {
- // Loop on the 4 embedded facets of each embedding facet
- FW_CFacetIterator ite2(ev, facet);
- short facetID = 0;
- for (ODFacet* embeddedFacet = ite2.First(ev); ite2.IsNotComplete(ev); embeddedFacet = ite2.Next(ev))
- {
- FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRects[facetID]);
- FW_CAcquiredODShape aqClipShape = FW_NewODShape(ev, clipRects[facetID]);
-
- // Change the facet's external transform
- // [LSD] normally I should not have to set the clip shape here since it
- // doesn't change. But if I don't do it the facets are not always
- // drawn... OpenDoc bug in ChangeGeometry?
- embeddedFacet->ChangeGeometry(ev, aqClipShape, externalTransform, NULL);
- facetID++;
- }
- }
- embeddingFrame->Invalidate(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy::FrameShapeRequested
- //----------------------------------------------------------------------------------------
- // We always want the embedded frame to have our frame shape
-
- ODShape* CEmbedProxy::FrameShapeRequested(Environment* ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFrame* odEmbeddedFrame,
- ODShape* requestedFrameShape)
- {
- FW_UNUSED(requestedFrameShape);
- FW_UNUSED(odEmbeddedFrame);
-
- return ((CEmbedFrame*)embeddingFrame)->CreateFrameShape(ev); // No FW_CAcquiredODShape because we are returning it
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy::GetExternalTransform
- //----------------------------------------------------------------------------------------
-
- ODTransform* CEmbedProxy::GetExternalTransform(Environment* ev, short rotation, short facetID, const FW_CRect& clipRect)
- {
- FW_CPoint origin(kBorder, kBorder);
- FW_Fixed x = clipRect.Width() + kBorder;
- FW_Fixed y = clipRect.Height() + kBorder;
-
- short position = (rotation + facetID) %4;
- switch (position)
- {
- case 0:
- switch (facetID)
- {
- case 1:
- origin.x -= x;
- break;
- case 3:
- origin.y -= y;
- break;
- case 2:
- origin.x -= x;
- origin.y -= y;
- break;
- }
- break;
- case 1:
- switch (facetID)
- {
- case 0:
- origin.x += x;
- break;
- case 3:
- origin.x += x;
- origin.y -= y;
- break;
- case 2:
- origin.y -= y;
- break;
- }
- break;
- case 3:
- switch (facetID)
- {
- case 0:
- origin.y += y;
- break;
- case 1:
- origin.x -= x;
- origin.y += y;
- break;
- case 2:
- origin.x -= x;
- break;
- }
- break;
- case 2:
- switch (facetID)
- {
- case 0:
- origin.x += x;
- origin.y += y;
- break;
- case 1:
- origin.y += y;
- break;
- case 3:
- origin.x += x;
- break;
- }
- break;
- }
-
- return ::FW_NewODTransform(ev, origin);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedFrame::CreateOneFacet
- //----------------------------------------------------------------------------------------
-
- ODFacet* CEmbedProxy::CreateOneFacet(Environment* ev,
- ODFacet* embeddingFacet,
- ODFrame* embeddedFrame,
- ODFacet* sibling,
- short rotation,
- short facetID,
- const FW_CRect& clipRect)
- {
- FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRect);
- FW_CAcquiredODShape clipShape = ::FW_NewODShape(ev, clipRect);
-
- return CreateFacet(ev,
- embeddingFacet,
- embeddedFrame,
- clipShape,
- externalTransform,
- NULL, // Canvas
- NULL, // biasCanvas
- sibling, // siblingFacet
- kODFrameInFront);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy::EmbeddedFacetBounds
- //----------------------------------------------------------------------------------------
-
- void CEmbedProxy::EmbeddedFacetBounds(Environment* ev, FW_CEmbeddingFrame* frame, FW_CRect* clipRects)
- {
- FW_CRect bounds = frame->GetBounds(ev);
- bounds.Place(FW_kFixed0, FW_kFixed0);
- bounds.Inset(kBorder);
-
- FW_CRect embeddedBounds = bounds;
- embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
-
- FW_CPoint embeddedMiddle(FW_Half(embeddedBounds.left + embeddedBounds.right), FW_Half(embeddedBounds.top + embeddedBounds.bottom));
-
- FW_CPoint middle(FW_Half(bounds.left + bounds.right), FW_Half(bounds.top + bounds.bottom));
-
- clipRects[0].Set(FW_kFixed0, FW_kFixed0, embeddedMiddle.x - kHalfBorder, embeddedMiddle.y - kHalfBorder);
- clipRects[1].Set(embeddedMiddle.x + kHalfBorder, FW_kFixed0, embeddedBounds.right, embeddedMiddle.y - kHalfBorder);
- clipRects[2].Set(embeddedMiddle.x + kHalfBorder, embeddedMiddle.y + kHalfBorder, embeddedBounds.right, embeddedBounds.bottom);
- clipRects[3].Set(FW_kFixed0, embeddedMiddle.y + kHalfBorder, embeddedMiddle.x - kHalfBorder, embeddedBounds.bottom);
- }
-
- //----------------------------------------------------------------------------------------
- // CEmbedProxy::CreateFacets
- //----------------------------------------------------------------------------------------
-
- short CEmbedProxy::CreateFacets(Environment* ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFacet* embeddingFacet,
- ODFrame* embeddedFrame,
- ODShape* proposedClipShape)
- {
- FW_UNUSED(proposedClipShape);
- FW_CRect bounds = embeddingFrame->GetBounds(ev);
- bounds.Place(FW_kFixed0, FW_kFixed0);
- bounds.Inset(kBorder);
-
- FW_CRect embeddedBounds = bounds;
- embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
-
- short nbFacet;
- if (fPart->FacetNumber() == cOneFacet)
- {
- CreateOneFacet(ev, embeddingFacet, embeddedFrame, NULL, 0, 0, embeddedBounds);
- nbFacet = 1;
- }
- else
- {
- FW_CRect clipRects[4];
- EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
- short rotation = fPart->GetRotation();
-
- ODFacet* siblingFacet = NULL;
- for (short facetID = 0; facetID < 4; facetID++)
- {
- ODFacet* newFacet = CreateOneFacet(ev,
- embeddingFacet,
- embeddedFrame,
- siblingFacet,
- rotation,
- facetID,
- clipRects[facetID]);
- if (siblingFacet == NULL)
- siblingFacet = newFacet;
- }
-
- nbFacet = 4;
- }
-
- return nbFacet;
- }
-
-